﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gridify.Test.Models;

namespace Gridify.Test.Services
{
    public class PersonGenerator
    {
        private readonly string[] _lastNames;
        private readonly string[] _firstNames;

        public PersonGenerator()
        {
            _firstNames = new[]
                              { 
                                  "Andy", "Max", "Maurice", "Russell", "Andrea", "Barney", "Robert", "Alastair", "Georg",
                                  "Frank", "Dick", "Iris", "Kurt", "Rosemary", "Patricia", "Ray", "Justin", "Alan", "Matthew",
                                  "Paul", "Mel", "John", "Graham", "Abbie", "Stephen"
                              };
            _lastNames = new[]
                             {
                                 "Garner", "Hall", "Hay", "Fisher", "Fry", "Carter", "Conley", "Stott", "Fleury",
                                 "Hopkins",
                                 "Dohetry", "Mansfield", "Barnard", "Boulton", "Coase", "Blacket", "Lintner", "Miller",
                                 "Levitt", "Kotler", "Ohno"
                             };
        }

        public IEnumerable<Person> GetRandomData(int personCount)
        {
            var r = new Random();

            var persons = Enumerable.Range(0, personCount)
                .Select(i => new
                                 {
                                     FirstName = _firstNames[r.Next(0, _firstNames.Length - 1)],
                                     LastName = _lastNames[r.Next(0, _lastNames.Length - 1)],
                                 })
                .Select((p, i) => new Person
                                  {
                                     Id = i,
                                     Firstname = p.FirstName,
                                     Lastname = p.LastName,
                                     Phone = "+562 " + r.Next(1000000, 9999999).ToString(),
                                     Email = string.Format("{0}.{1}@supermail.com", p.FirstName.ToLower(), p.LastName.ToLower())
                                  }).ToArray();
            return persons;
        }
    }
}